
*this program does not use absolute paths
*it assumes that upon starting Stata, the user sets working directory 
*the working directory should be where data files wdidataMat2016.dta and FAid_final.dta are saved

clear
*load WDI data
*the original data was loaded using Stata command "wbopendata" comented out below
*the retrieval took place in May 2016 and the retrieved file was saved as wdidataMay2016.dta
*wbopendata, indicator(SP.DYN.IMRT.IN) clear long 
*save wdidataMay2016, replace
use wdidataMay2016, clear
rename countrycode risocode
rename sp_dyn_imrt_in imr
keep risocode year imr
sort risocode year

*merge in data from U.S. Food Aid and Civil Conflict� by Nathan Nunn and Nancy Qian 
*(American Economic Review 2014, 104(6): 1630-1666 http://dx.doi.org/10.1257/aer.104.6.1630)
merge 1:1 risocode year using FAid_final
drop if _merge~=3
drop if year<1981 | year>2006
drop if risocode=="GNQ" //make sample comparable to Nunn, Qinn
rename recipient_country country
rename wheat_aid uswheat_aid
rename US_wheat_prod uswheat_prod
rename s2unUSA unvotes
rename fadum_avg avg_fap
rename intra_state intrstate_war
rename intra_state_onset onset
egen avg_annual_precip = rowmean(all_Precip_jan all_Precip_feb all_Precip_mar all_Precip_apr ///
     all_Precip_may all_Precip_jun all_Precip_jul all_Precip_aug all_Precip_sep all_Precip_oct all_Precip_nov all_Precip_dec)
keep uswheat_aid avg_fap uswheat_prod country year avg_annual_precip uswheat_prod ///
     intrstate_war any_war intensity imr total_population unvotes onset USprod_Cabbages USprod_Carrots_turnips ///
	 USprod_Cotton_lint USprod_Grapefruit USprod_Grapes USprod_Lettuce ///
	 USprod_Onions_dry USprod_Oranges USprod_Peaches_nectarines USprod_Watermelons
save rawdata, replace
